﻿
@{
    ViewBag.Title = "新增模块";
}
<form class="layui-form layui-form-pane" lay-filter="">
    <div class="layui-form-item">
        <label class="layui-form-label">上级模块</label>
        <div class="layui-input-inline">
            <div id="moduleSelect"></div>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">模块类型</label>
        <div class="layui-input-inline">
            <input type="radio" name="ModuleType" value="0" title="目录" checked>
            <input type="radio" name="ModuleType" value="1" title="菜单">
            <input type="radio" name="ModuleType" value="2" title="按钮">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">模块名称</label>
        <div class="layui-input-inline">
            <input type="text" name="ModuleName" autocomplete="off" class="layui-input" placeholder="必填项" lay-verify="required" />
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">模块描述</label>
        <div class="layui-input-inline">
            <input type="text" name="ModuleDesc" autocomplete="off" class="layui-input" lay-verify="required" />
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">模块链接</label>
        <div class="layui-input-inline">
            <input type="text" name="ModuleUrl" autocomplete="off" class="layui-input" />
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">模块图标</label>
        <div class="layui-input-inline">
            <input type="text" name="ModuleIcon" autocomplete="off" class="layui-input" />
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">模块排序</label>
        <div class="layui-input-inline">
            <input type="text" name="ModuleSort" autocomplete="off" class="layui-input" />
        </div>
    </div>
    <div class="layui-form-item" style="text-align:center;">
        <button class="layui-btn" lay-submit lay-filter="save">保存</button>
        <button class="layui-btn" id="cancel">取消</button>
    </div>
</form>
<script src="~/Content/lib/xm-select.js"></script>
<script type="text/javascript">
    layui.use(['form', 'jquery'], function () {
        var form = layui.form;
        var $ = layui.jquery;
        var xm = xmSelect.render({
            el: '#moduleSelect',
            name: 'ParentID',
            filterable: true,
            model: { label: { type: 'text' } },
            radio: true,
            clickClose: true,
            tree: {
                show: true,
                strict: false,
                expandedKeys: true,
            },
            height: 'auto',
            data: []
        })
        $.ajax({
            url: 'MenuSelects',
            success: function (res) {
                xm.update({
                    data: res
                })
            }
        });

        form.on("submit(save)", function (formdata) {
            $.ajax({
                url: 'Add',
                data: formdata.field,
                success: function (res) {
                    layer.alert(res.msg, function (index) {
                        layer.close(index);
                        if (res.count > 0) {
                            parent.layer.closeAll();
                        }
                    })
                }
            });
            return false;
        })
        $("#cancel").click(function () {
            parent.layer.closeAll();
        })
    })
</script>

